<?php
namespace app\listener\admin;

use app\common\service\webscoket\CacheRedisService;
use think\facade\Log;
use Swoole\Process;
use think\facade\Queue;

class CreateTimerListener
{
    public function handle($server)
    {
        /********************当服务启动时判断队列是否有任务，没有清空一次缓存*****************************/
        if (Queue::size() <= 0) {
            $del_assign = CacheRedisService::del('OrderAssignListener');
            $del_schedule = CacheRedisService::del('OrderScheduleListener');
        }
        // 创建子进程
//        $process = new Process(function(Process $worker){
//            Log::info("子进程启动，PID: {$worker->pid}");
//            app()->event->trigger('create_timer');
//        });

        // 启动子进程
//        $pid = $process->start();
        // 监听子进程退出事件
//        Process::signal(SIGCHLD, function($sig) {
//            while($ret = Process::wait(false)) {
//                Log::info("子进程退出，PID: {$ret['pid']}");
//            }
//        });
    }
}
